import { arr2Tree } from '@/utils'

export const modules = import.meta.glob(['@/layout/index.vue', '@/views/**'])

//懒加载laylout防止菜单折叠

/**
 * router.removeRoute限制：路由必须有name
 * el-memu限制：path必须根路径
 * 面包屑导航限制：父路由必须包含在子路由里面，path不能包含'/'
 * showLink 显示菜单
 * icon element图标
 */
export let authorityRoutes = []

export function initAuthorityRoutes() {
  let authMenus: any = localStorage.getItem('authMenus')

  if (authMenus) {
    authMenus = JSON.parse(authMenus)

    authMenus = authMenus.map((menu) => {
      menu.component = modules[menu.component]
      return menu
    })

    authMenus = arr2Tree(authMenus)

    authorityRoutes = authMenus
  }
}
